package com.itcast.demo_one

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.LinearLayoutManager
import com.itcast.demo_one.adapter.MyAdapter

class RecyclerViewActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_recycler_view)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        // 1.1 初始化RecyclerView控件
        val recyclerView = findViewById<RecyclerView>(R.id.recycler_view)
        // 1.2 创建布局管理器
        // context - 当前上下文
        // orientation - 布局方向为水平(HORIZONTAL), VERTICAL
        // reverseLayout - false表示不反向排列
        // 线性布局
        // recyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
        // 宫格布局
        recyclerView.layoutManager = GridLayoutManager(this, 3)

        // 1.3 准备模拟数据
        val items = List(20) { i -> "黑马程序员 ${i + 1}" }
        // 1.4 创建适配器
        val adapter = MyAdapter(items)
        // 1.5 设置适配器
        recyclerView.adapter = adapter


    }
}